package org.bizming.web.action;

import java.io.IOException;
import java.util.List;

import org.bizming.base.BaseErrCode;
import org.bizming.base.BaseException;
import org.bizming.medicine.model.help.OfferCompany;
import org.bizming.medicine.service.OfferCompanyService;
import org.bizming.web.util.WebUtil;

public class OfferCompanyAction {

	private OfferCompanyService offerCompanyService;

	private OfferCompany oc;

	/** 修改数据 */
	public String addOrUpdate() {
		int errCode = BaseErrCode.SUCCESS;

		try {
			if (null != oc && null == oc.getId()) {
				offerCompanyService.add(oc);
			} else {
				offerCompanyService.update(oc);
			}

			WebUtil.getResponse().sendRedirect(
					WebUtil.getRequest().getContextPath() + "/offerCompany!selectList.action");
			return null;
		} catch (BaseException e) {
			errCode = e.getErrCode();
		} catch (Exception e) {
			e.printStackTrace();
			errCode = BaseErrCode.SERVER_ERROR;
		}
		WebUtil.getRequest().setAttribute("code", errCode);
		WebUtil.getRequest().setAttribute("o", oc);
		return "addOrUpdate_exception";
	}

	/** 查看数据 */
	public String view() {
		OfferCompany company = null;
		if (null != oc && null != oc.getId()) {
			company = offerCompanyService.get(oc.getId());
		}
		WebUtil.getRequest().setAttribute("o", company);
		return "view";
	}

	/**
	 * 删除数据
	 * 
	 * @throws IOException
	 */
	public String remove() throws IOException {

		if (null != oc && null != oc.getId()) {
			offerCompanyService.remove(oc.getId());
		}
		WebUtil.getResponse().sendRedirect(
				WebUtil.getRequest().getContextPath() + "/offerCompany!selectList.action");
		return null;
	}

	/** 获取数据 */
	public String selectList() {

		List<OfferCompany> list = offerCompanyService.selectList();
		WebUtil.getRequest().setAttribute("list", list);

		return "selectList";
	}

	// ===============================================
	public OfferCompanyService getOfferCompanyService() {
		return offerCompanyService;
	}

	public void setOfferCompanyService(OfferCompanyService offerCompanyService) {
		this.offerCompanyService = offerCompanyService;
	}

	public OfferCompany getOc() {
		return oc;
	}

	public void setOc(OfferCompany oc) {
		this.oc = oc;
	}

}
